package experiment3;
import java.io.Serializable;
public class Course implements Serializable {
	private String courseName;
	private int courseId;
	private String teacher;
	private String place;
	private String time;
	private Student[] students;

	public Course(int courseId, String courseName, String string, String place,
			String time) {
		super();
		this.courseId = courseId;
		this.courseName = courseName;
		this.place = place;
		this.time = time;
		this.setTeacher(string);
		students = new Student[30];
	}

	public String toString() {
		return "[" + courseId + ", " + courseName + "," + teacher + "," + place + "," + time + "]";
	}

	public Course(int courseId, String courseName, String place, String time) {
		super();
		this.courseId = courseId;
		this.courseName = courseName;
		this.place = place;
		this.time = time;
		students = new Student[30];
	}

	public Course(int courseId, String courseName, String place) {
		super();
		this.courseId = courseId;
		this.courseName = courseName;
		this.place = place;
		students = new Student[30];
	}

	public Course(int courseId, String courseName) {
		super();
		this.courseId = courseId;
		this.courseName = courseName;
		students = new Student[30];
	}

	public Course() {
		super();
		students = new Student[30];
	}

	public int getId() {
		return this.courseId;
	}

	public void setId(int id) {
		this.courseId = id;
	}

	public String getName() {
		return this.courseName;
	}

	public void setName(String name) {
		this.courseName = name;
	}

	public String getTeacher() {
		return teacher;
	}

	public void setTeacher(String string) {
		this.teacher = string;
	}

	public String getPlace() {
		return this.place;

	}

	public void setPlace(String place) {
		this.place = place;
	}

	public String getTime() {
		return this.time;

	}

	public void setTime(String time) {
		this.time = time;
	}

	public boolean addStudent(Student stu) {
		boolean flag = false;// 标志值：是否加入成功
		if (!isSelectedStudent(stu) && isNullStudent(stu)) {
			for (int i = 0; i < students.length; i++) {
				if (students[i] == null) {
					students[i] = stu;
					flag = true;
					break;
				}
			}
		}
		return flag;
	}

	public boolean removeStudent(Student stu) {
		boolean flag = false;
		if (isSelectedStudent(stu)) {// 选过这门课
			for (int i = 0; i < students.length; i++) {
				if (students[i] == stu) {
					students[i] = null;
					flag = true;
					break;
				}
			}
		}
		return flag;
	}

	public void displayStudent() {
		System.out.println("选择的课程：" + this.courseName + "的学生有:");
		for (Student s : students) {
			if (s != null) {
				System.out.print(s.getStuName() + " ");
			}
		}
		System.out.println();
	}

}